#
# To execute this run script on your Linux host you have to do some
# preparation:
#
# 1) Setup a TAP device:
#    ! export USER=[YOUR_USER_NAME]
#    ! export TAP_DEV=tap0
#    ! sudo ip tuntap add dev $TAP_DEV mode tap user $USER
#    ! sudo ip address flush dev $TAP_DEV
#    ! sudo ip address add 10.0.2.1/24 brd 10.0.2.255 dev $TAP_DEV
#    ! sudo ip link set dev $TAP_DEV addr 02:00:00:ca:fe:01
#    ! sudo ip link set dev $TAP_DEV up
#
# 2) Now, start the test and connect using your favorite HTTP client, e.g.:
#    ! cd build/x86_64
#    ! make run/lwip_lx KERNEL=linux BOARD=linux
#    ! lynx -dump http://10.0.2.55
#
# 3) Clean up your Linux when done testing:
#    ! sudo ip tuntap delete $TAP_DEV mode tap
#

assert {[have_spec linux]}

build {
	core init timer lib/ld lib/libc lib/vfs lib/vfs_lwip
	driver/nic test/lwip/http_srv server/nic_router server/report_rom
}

create_boot_directory

install_config {
<config verbose="yes">

	<parent-provides>
		<service name="ROM"/>
		<service name="IRQ"/>
		<service name="IO_MEM"/>
		<service name="IO_PORT"/>
		<service name="PD"/>
		<service name="RM"/>
		<service name="CPU"/>
		<service name="LOG"/>
	</parent-provides>

	<default-route>
		<any-service> <parent/> <any-child/> </any-service>
	</default-route>

	<default caps="100" ram="1M"/>

	<start name="timer">
		<provides> <service name="Timer"/> </provides>
	</start>

	<start name="devices_report_rom" ram="1200K">
		<binary name="report_rom"/>
		<provides> <service name="Report"/> <service name="ROM"/> </provides>
		<config verbose="yes"/>
	</start>

	<start name="linux_nic" ld="no" ram="8M">
		<config>
			<report mac_address="true"/>
		</config>
		<route>
			<service name="Uplink"> <child name="nic_router"/> </service>
			<service name="Report"> <child name="devices_report_rom"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

	<start name="nic_router" caps="200" ram="10M">
		<provides>
			<service name="Nic"/>
			<service name="Uplink"/>
		</provides>
		<config verbose_domain_state="yes">

			<policy label_prefix="test-lwip_httpsrv" domain="downlink"/>
			<policy label_prefix="linux_nic"         domain="uplink"/>

			<domain name="uplink" interface="10.0.2.55/24" gateway="10.0.2.1">

				<nat domain="downlink"
				     tcp-ports="16384"
				     udp-ports="16384"
				     icmp-ids="16384"/>

				<tcp-forward port="443" domain="downlink" to="10.0.3.2"/>
				<tcp-forward port="80"  domain="downlink" to="10.0.3.2"/>

			</domain>

			<domain name="downlink" interface="10.0.3.1/24"/>

		</config>
	</start>

	<start name="test-lwip_httpsrv" ram="5M">
		<config ld_verbose="true">
			<vfs>
				<dir name="dev"> <log/> </dir>
				<dir name="socket"> <lwip ip_addr="10.0.3.2" netmask="255.255.255.0" gateway="10.0.3.1"/> </dir>
			</vfs>
			<libc stdout="/dev/log" stderr="/dev/log" socket="/socket"/>
		</config>
	</start>

</config>
}

build_boot_image [build_artifacts]

run_genode_until forever

# vi: set ft=tcl :
